//
//  FirstViewController.m
//  回调Block
//
//  Created by clz on 2019/7/31.
//  Copyright © 2019年 clz. All rights reserved.
//

#import "FirstViewController.h"
#import "TestView.h"


@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor=[UIColor redColor];
    [button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:18];
    button.frame = CGRectMake(0, 100, 300, 50);
    
    [self.view addSubview:button];
    
    TestView *view = [[TestView alloc]init];
    view.frame = CGRectMake(self.view.frame.size.width/2.0 - 150, 300, 300, 50);
    [self.view addSubview: view];
    //循环引用
    __weak typeof(self) weakSelf = self;
    __block NSInteger i = 1;
    view.changeValueBlock = ^{
        weakSelf.view.backgroundColor = [UIColor yellowColor];
        
        i = 2;
        
        NSLog(@"i = %ld",(long)i);
        
    };
    
    
    
    
    
}

- (void)backAction:(UIButton *)sender{
    
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


- (void)dealloc{
    NSLog(@"释放");
}


@end
